home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CBM Funet Archive
/
cbm-funet-archive-2003.iso
/
cbm
/
demodisks
/
drives
/
1581-demo.lzh
/
rel file example
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
1994-10-19
|
5KB
|
142 lines
10 rem use this program to learn how
20 rem create and use relative files.
30 rem it is flexible enough for you
40 rem to customize it for your use.
50 rem
55 poke53280,0:poke53281,0
75 gosub1460
80 ll$=chr$(13) :rem this is the field delimiter used when writing records
90 input"[155] what is the file name";nm$: rem maximum 16 character name.
100 iflen(nm$)>0andlen(nm$)<17then120
110 print"[145][145][145]":goto90
120 input"[155] on what device number";dv
130 open15,dv,15,"i0": rem initialize the disk drive.
140 open 8,dv,8,"0:"+(nm$)
150 input#15,e,e$,a,b :rem read the error channel.
160 if e=62 then 200
170 if e=0 then 180:printe,e$,a,b:goto 1270
180 print"[155] (file exists)"
190 goto 280
200 print"[155] (new file)"
210 close8
220 input"[155] how many characters in each record";ln :rem maximum 254.
230 ln=int(ln):ifln>0andln<255then250
240 print"[145][145][145]":goto220
250 open8,dv,8,"0:"+(nm$)+",l,"+chr$(ln)
260 gosub 1110
280 print"[155] do you want to : "
290 printspc(7)"r[155]ead a record"
300 printspc(7)"w[155]rite a record"
310 printspc(7)"s[155]et up a file"
320 printspc(7)"q[155]uit "
330 print
340 a$=""
350 geta$
360 if a$="r" then 420
370 if a$="w" then 640
380 if a$="s" then 890
390 if a$="q" then 1050
400 goto350
410 :
420 rem this section positions to and reads a record.
425 gosub 1460:print
430 input"[155]read what record number";rn
440 gosub1060 :rem calculate the low byte/high byte pointer.
450 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem position command
460 gosub 1110 :rem check the error channel
470 if e=50 thenprint"[155]record number too large":goto560
480 input#8,aa$,bb$,cc$,dd$,ee$ :rem read in the fields.
490 gosub 1110 :rem check the error channel
500 print"[155]record number";rn;"[157] contains:":print
510 printspc(8)"[155]name: ";aa$
520 printspc(5)"[155]address: ";bb$
530 printspc(8)"[155]city: ";cc$
540 printspc(7)"[155]state: ";dd$
550 printspc(4)"[155]zip code: ";ee$
560 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1):rem reposit'n for safety
570 gosub 1110 :rem check the error channel
580 print"[155]read another record?";:a$=""
590 geta$:if (a$<>"y") and (a$<>"n") then 590
600 print
610 if a$="y"thengoto425
620 gosub1460:goto280 :rem do main menu
630 :
640 rem this section positions to and writes a record.
645 gosub1460:print
650 input"[155]write what record number";rn:print
660 input"[155] name: ";aa$ :rem change the prompts to ask for data needed
670 input"[155] address: ";bb$ :rem in your particular application.
680 input"[155] city: ";cc$ :rem any number of fields can be used as long as
690 input"[155] state: ";dd$ :rem they fit within the record length you
700 input"[155] zip code: ";ee$ :print:rem specified when creating the file.
710 rc$=aa$+ll$+bb$+ll$+cc$+ll$+dd$+ll$+ee$
720 rem rc$ is the string containing all the fields for the record.
730 rem remember the max length for rc$ is 254 characters.
740 gosub1060 :rem calculate the low byte/high byte pointer.
750 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem position command
760 gosub 1110 :rem check the error channel
770 if e=50 thenprint"[155]the dos will expand the file now"
780 print#8,rc$ :rem write the record
790 gosub 1110 :rem check the error channel
800 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem reposit'n for safety
810 gosub 1110 :rem check the error channel
820 print
830 print"[155]write another record?";:a$=""
840 geta$:if (a$<>"y") and (a$<>"n") then 840
860 if a$="y"then645
870 gosub1460:goto280 :rem do main menu
880 :
890 rem this section positions to and writes the highest record number.
900 rem although not entirely necessary, writing and updating long files
910 rem is speeded when this procedure is used. this will cause the
920 rem dos side sector list to be created entirely at the start rather
930 rem than being appended for each new higher record number.
940 print"[155]what is the highest record number"
950 input"[155]you want to use";rn
960 gosub1060 :rem calculate the low byte/high byte pointer.
970 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem position command
980 gosub 1110 :rem check the error channel
990 if e=50 thenprint"[155]the dos will expand the file now"
1000 print#8,chr$(255) :rem
1010 gosub 1110 :rem check the error channel
1020 print#15,"p"+chr$(96+8)+chr$(rl)+chr$(rh)+chr$(1) :rem reposit'n for safety
1030 gosub 1110 :rem check the error channel
1040 goto280 :rem go to the menu
1050 close8:close15:end
1060 rem this subroutine calculates the record number pointer
1070 rem in the low byte/high byte format.
1080 rem rn (record number) is used to calculate rl and rh.
1090 rh=int(rn/256):rl=rn-(256*rh) : rem rl is low -- rh is high.
1100 return
1110 rem this is the disk drive error checking subroutine.
1120 input#15,e,e$,a,b :rem read the error channel.
1130 if e=0 then return :rem there is no error if e=0.
1140 rem e=50 (record not present) any time a record number pointer is
1150 rem positioned beyond the current highest record number.
1160 if e=50 then return
1170 if e<>51 then 1220
1180 print:print"[155]error-51, record too long."
1190 print"[155](return counts as a character)"
1200 gosub 1280
1210 return
1220 print"[155]there is an i/o problem"
1230 print"error number is";e,e$
1240 print"at track";a;" sector";b
1250 if e=70 thenprint"[155]make sure you input the correct record"
1260 if e=70 thenprint"[155]length for an existing file name."
1270 close8:close15:end
1280 print"[155]computing allowable record length":print" (please wait...)"
1290 if ln<>0 then 1330
1300 close8
1310 for ln=1 to 254:open8,dv,8,"0:"+(nm$)+",l,"+chr$(ln):input#15,e:ife=0then1330
1320 close 8:next ln:print"[155]unable to compute record length!":goto1270
1330 print"[145] "
1340 print"[145][155]allowable record length = ";ln
1350 return
1450 rem title subroutine
1460 print"[147][155] [192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192]"
1465 printspc(6)"[159] relative file demo "
1470 printspc(6)"(name and address file)"
1475 print"[155] [192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192][192]"
1480 return